package com.salton123.qa.demo;

import android.util.Log;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * User: newSalton@outlook.com
 * Date: 2018/12/1 5:56 PM
 * ModifyTime: 5:56 PM
 * Description:
 */
public class MyUtil {

    public static void reg() {
        String str = "12-01 18:12:57.293\n" +
            "    \n" +
            "    java.lang.Thread.sleep(Native Method)\n" +
            "    java.lang.Thread.sleep(Thread.java:373)\n" +
            "    java.lang.Thread.sleep(Thread.java:314)\n" +
            "    android.os.SystemClock.sleep(SystemClock.java:122)\n" +
            "    TestBlockAty$1.onClick(TestBlockAty.java:32)\n" +
            "    android.view.View.performClick(View.java:6312)\n" +
            "    android.view.View$PerformClick.run(View.java:24811)\n" +
            "    android.os.Handler.handleCallback(Handler.java:793)\n" +
            "    android.os.Handler.dispatchMessage(Handler.java:99)\n" +
            "    android.os.Looper.loop(Looper.java:176)\n" +
            "    android.app.ActivityThread.main(ActivityThread.java:6651)\n" +
            "    java.lang.reflect.Method.invoke(Native Method)\n" +
            "    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)\n" +
            "    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)";

        Log.e("regex-replace", str.replaceAll("(\\d+)-(\\d+)\\s+(\\d+):(\\d+):(\\d+).\\d+", ""));
        // Pattern pattern = Pattern.compile("(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\\s+(20|21|22|23|[0-1]\\d):[0-5]\\d:[0-5]\\d.\\d+");
        Pattern pattern = Pattern.compile("(\\d+)-(\\d+)\\s+(\\d+):(\\d+):(\\d+).\\d+");
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()) {
            Log.e("regex", matcher.group());
        } else {
            Log.e("regex", "not found ");
        }
    }

    public String repalceAll(String oldStr) {
        return oldStr.replaceAll("(\\d+)-(\\d+)\\s+(\\d+):(\\d+):(\\d+).\\d+", "");
    }
}
